package org.nudt.system.controller

import org.nudt.common.model.PageData
import org.nudt.common.model.ResponseData
import org.nudt.common.model.User
import org.nudt.common.model.vo.PlayLogVO
import org.nudt.system.service.PlayLogService
import org.nudt.system.service.SysUserService
import org.springframework.data.domain.PageRequest
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/v1/system/user")
class SysUserController(private val playLogService: PlayLogService, private val sysUserService: SysUserService) {
    
    @GetMapping("/log")
    fun getPlayLogByAppid(
        @RequestParam(required = false, defaultValue = "") appid: String,
        @RequestParam(required = false, defaultValue = "1") page: Int,
        @RequestParam(required = false, defaultValue = "10") size: Int
    ): ResponseData<PageData<PlayLogVO>> {
        return if (appid.isEmpty()) {
            ResponseData.success(playLogService.getPLayLog(PageRequest.of(page - 1, size)))
        } else {
            ResponseData.success(playLogService.getPLayLogByAppid(appid, PageRequest.of(page - 1, size)))
        }
    }
    
    @GetMapping("/list")
    fun getUserList(
        @RequestParam(required = false) nickname: String?,
        @RequestParam(required = false) gender: Int?,
        @RequestParam(required = false) appVersion: String?,
        @RequestParam(required = false) osVersion: String?,
        @RequestParam(required = false, defaultValue = "1") page: Int,
        @RequestParam(required = false, defaultValue = "10") size: Int
    ): ResponseData<PageData<User>> {
        return ResponseData.success(sysUserService.getUserList(nickname, gender, appVersion, osVersion, PageRequest.of(page - 1, size)))
    }
}